package com.hllxd.hism.passport.login.gateway.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;

/**
 * Created by root on 17-8-12.
 */
public class TraceUtil {

    // 时间+随机数的生产方法
    public static String random() {

        Random random = new Random();
        return Integer.toString(random.nextInt(Integer.MAX_VALUE), 36);
    }

    public static String time(String format) {

        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat df = new SimpleDateFormat(format);
        df.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        return df.format(date);
    }

    public static String newTraceId(){

        String date = time("yyyyMMddHHmmssSSS");
        String rnd = random();
        return date + rnd;
    }
    public static String newTraceTs(){
        return time("yyyyMMddHHmmssSSS");
    }


    public static String time(String format,long ms) {

        Date date = new Date(ms);
        SimpleDateFormat df = new SimpleDateFormat(format);
        df.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        return df.format(date);
    }

    public static void main(String[] args){
        System.out.println(newTraceId());
    }
}
